package com.example.myapplication.api

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitFactory {
    const val API_KEY = "8afaf9ed720b8e8cdb5ebfc28ba532e9"
    private const val BASE_URL = "https://restapi.amap.com/"

    fun getRetrofit(): Retrofit {
        // 初始化 Retrofit
        val retrofit = Retrofit.Builder()
            .baseUrl(BASE_URL)
            .client(getClient())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
        return retrofit
    }

    fun getClient(): OkHttpClient {
        val interceptor = HttpLoggingInterceptor()
        val client = OkHttpClient.Builder()
            .addInterceptor(interceptor) // 添加日志拦截器
            .build()

        return client
    }
}